package edu.umb.cs.antmanager.manager;

import static edu.umb.cs.antmanager.common.Constants.*;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import edu.umb.cs.antmanager.common.AgentInterface;

/**
 * Used by the manager to create a connection to the agent.
 * 
 * @author 2009CS682-3UMB_AntManager
 * 
 */
public class RMIServerConnector {

	/**
	 * Find the agent's Remote Object in the Agent's Regsitry
	 * 
	 * @param machineName
	 *            Agent's host name
	 * @return the agent's server interface
	 * @throws MalformedURLException
	 * @throws RemoteException
	 * @throws NotBoundException
	 */
	public static AgentInterface createAgentConnector(String machineName)
			throws MalformedURLException, RemoteException, NotBoundException {
		return (AgentInterface) Naming.lookup("rmi://" + machineName + ":"
				+ AGENT_PORT + "/" + AGENT_SERVER_NAME);
	}

}
